package test;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Jisuan {

    public static void  and(){
        Mat image0 = Mat.zeros(200, 200, CvType.CV_8UC3);
        Rect rect=new Rect(50,50,100,100);
        Mat mat = new Mat(image0, rect);

        Mat image1 = Mat.zeros(200, 200, CvType.CV_8UC3);
        Rect rect2=new Rect(100,100,100,100);
        Mat mat2 = new Mat(image1, rect2);

        Mat mat3=new Mat();
        Core.bitwise_and(mat, mat2,mat3);

        HighGui.imshow("image0", mat);
        HighGui.imshow("image1", mat2);
        HighGui.imshow("mat3", mat3);
    }

    public static void  read(){
        Mat imread = Imgcodecs.imread("D:\\20200907153450.jpg");
        Mat bw=new Mat();
        Imgproc.cvtColor(imread, bw, Imgproc.COLOR_BGR2GRAY);
        Imgproc.threshold(bw, bw, 100, 255,  Imgproc.THRESH_OTSU);
        HighGui.imshow("Binary Image", bw);

//        HighGui.imshow("image0", imread);
    }

    public static void main(String[] args) {

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Jisuan.read();
        HighGui.waitKey(0);
        //![display]

        System.exit(0);
    }
}
